package io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * @author Luka
 * @date 2021/05/28 14:19
 *
 * 使用缓冲流玩成文件赋值操作
 *
 * 缓冲流
 * java.io.BufferedInputStream和BufferedOutputStream
 * 缓冲流是一对高级流,他的作用是提高数据的读写效率
 *
 * 缓冲流内部维护一个8k字节数组,无论我们读写方式是什么(随机读写,块读写)
 * 缓冲流都会同意转换撑块读写来保证读写效率
 *
 **/
public class CopyDemo3 {
    public static void main(String[] args) throws Exception {
        FileInputStream fis = new FileInputStream("D:\\IDEA_WorkSpace\\JSD2104_SE/tts9.rar");
        BufferedInputStream bis = new BufferedInputStream(fis);

        FileOutputStream fos = new FileOutputStream("D:\\IDEA_WorkSpace\\JSD2104_SE/tts91.rar");
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        int d;
        long start = System.currentTimeMillis();
        while ((d = bis.read())!=-1){
            bos.write(d);
        }

        long ends = System.currentTimeMillis();
        System.out.println("复制完了,用时"+(ends-start)+"毫秒");

        bis.close();
        bos.close();

    }
}